package BasicMath;

public class EuclideanDistance {
	
	/**
	 * 
	 * @param valuesObj1 an array of values that corresponds to the object's location in each dimension.
	 * @param valuesObj2 an array of values that corresponds to the object's location in each dimension.
	 * @return Returns the Euclidean distance of the two objects.
	 * @throws Exception
	 */
	public static double GetDistance(Double[] valuesObj1, Double[] valuesObj2) throws Exception
	{
		//O(3n) where n is the number of dimensions
		double result;
		
		if (valuesObj1.length != valuesObj2.length)
			throw new Exception("Arrays must be of the same length");
		
		double radicandSum = 0;
		for (int i = 0; i < valuesObj1.length; i++)
		{
			radicandSum += Math.pow(valuesObj1[i]-valuesObj2[i], 2);
		}
		
		result = Math.sqrt(radicandSum);
		
		return result;
	}
}
